package com.example.langchanin4jdemo1.controller;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.ChatMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.response.ChatResponse;

public class HelloWorldDemo02 {
    /**
     * ChatMessage:AiMessage UserMessage记录上下文
     * @param args
     */
    public static void main(String[] args) {
        ChatLanguageModel model = QwenChatModel.builder()
                .apiKey("sk-875dd6ef14244431acdc7ccb974f5bfe")
                .modelName("qwen-plus")
                .build();

        UserMessage userMessage = UserMessage.from("你好，你是谁");
        ChatResponse response = model.chat(userMessage);
        AiMessage aiMessage = response.aiMessage();
        System.out.println(aiMessage.text());

        UserMessage userMessage2 = UserMessage.from("请重复一次");

        ChatResponse chatResponse = model.chat(userMessage, aiMessage, userMessage2);
        System.out.println(chatResponse.aiMessage().text());
    }
}
